home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 10
/
AACD 10.iso
/
AACD
/
Online
/
SpeakFreely
/
src
/
lpc10
/
round.c
< prev
next >
Wrap
Text File
|
2000-05-18
|
577b
|
27 lines
/* This routine takes in a floating point number and rounds it to */
/* the nearest integer. */
int
round(afloat)
double afloat;
{
int rounded_int;
/* this will truncate afloat */
rounded_int = afloat;
/* positive and negative numbers are handled differently */
if (afloat < 0)
{
/* if the fractional part is -.5 or less round down */
if (afloat - rounded_int <= -.5) rounded_int--;
}
else
{
/* if the fractional part is .5 or greater round up */
if (afloat - rounded_int >= .5) rounded_int++;
}
return(rounded_int);
}